<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
	<script type="text/javascript">
	

	var Deferred = function (value) {
	    if (value && typeof value.then === "function")
	        return value;
	    return {
	        then: function (callback) {
	        	var result = callback(value);
	            return Deferred(result);
	        }
	    };
	};


	Deferred("100")
		.then(function(value){
	    	console.log(value); // 100
			return 2 * value;
		})
		.then(function(value){
	    	console.log(value); // 200
		});
		
	</script>
</head>
<body>

</body>
</html>